<?php

class PlanApp extends MemberbaseApp
{
	function import(){
		if (!IS_POST) {

			$this->display('import.html');
		}else{
			$db = &db();
			$sqldb=&sqldb();
			$file = $_FILES['file_card'];
			if ($file['error'] == UPLOAD_ERR_NO_FILE) // 没有文件被上传
			{
				$this->show_warning('没有要导入的文件','','index.php?app=plan&act=import');
				exit();
			}
			import('uploader.lib');             //导入上传类
			$uploader = new Uploader();
			$uploader->allowed_type(EXCEL_FILE_TYPE); //限制文件类型
			$uploader->addFile($_FILES['file_card']);//上传excel
			if (!$uploader->file_info())
			{
				$this->show_warning('上传文件失败','','index.php?app=plan&act=import');
				exit();
			}
			// 指定保存位置的根目录
			$uploader->root_dir(ROOT_PATH);

			$imgname=gmtime();
			// 上传
			$file_path = $uploader->save('data/files/excel', $imgname);  //保存到指定目录
			include_once(ROOT_PATH.'/excel/toexcel/PHPExcel/IOFactory.php');
			include_once(ROOT_PATH.'/excel/toexcel/PHPExcel/Reader/Excel5.php');
			include_once(ROOT_PATH.'/excel/toexcel/PHPExcel.php');
			$objPHPExcel = PHPExcel_IOFactory::load(ROOT_PATH.'/'.$file_path);
			$sheet = $objPHPExcel->getSheet(0);
			$highestRow = $sheet->getHighestRow();           //取得总行数
			$highestColumn = $sheet->getHighestColumn(); //取得总列数

			$uid=$this->visitor->get("user_id");
			$uid=empty($uid)?0:intval($uid);
			if(empty($uid)){
				$this->show_warning('您还没有登录，请先登录','','index.php?app=plan&act=import');
				exit();
			}

			$db=&db();
			$sql="select depot,del,company,user_name from zys_member where user_id=".$uid;
			$u=$db->getRow($sql);

			if($u['del']){
				$this->show_warning('用户被禁用，如有疑问请联系客服','','index.php?app=plan&act=import');
				exit();
			}

			if(!$u['depot']){
				$this->show_warning('用户还没有被系统确认，无法预定','','index.php?app=plan&act=import');
				exit();
			}

			$sql="select * from T_SALM where SAL_NO='".$u['depot']."'";
			$salm=$sqldb->getRow($sql);

			if(!$salm){
				$this->show_warning('用户还没有被系统确认，无法预定','','index.php?app=plan&act=import');
				exit();
			}

			for($j=2;$j<=$highestRow;$j++)                        //从第二行开始读取数据
			{
				$SHIP_OVOY = $objPHPExcel->getActiveSheet()->getCell("D".$j)->getValue();
				$TD_NO = $objPHPExcel->getActiveSheet()->getCell("F".$j)->getValue();
				$XX = $objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();
				$QTY = $objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();
				$REM = $objPHPExcel->getActiveSheet()->getCell("J".$j)->getValue();
				$CUS_NO = $objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();
				$OVOY = $objPHPExcel->getActiveSheet()->getCell("E".$j)->getValue();

				$P_ADD = $objPHPExcel->getActiveSheet()->getCell("H".$j)->getValue();
				$EUSE_DD = $objPHPExcel->getActiveSheet()->getCell("G".$j)->getValue();
				$jj_flag = $objPHPExcel->getActiveSheet()->getCell("I".$j)->getValue();

				if(!$CUS_NO){
					continue;
				}

				$sql="select 1 from zys_shippingline where code='".$CUS_NO."'";
				$data=$db->getOne($sql);

				if(!$data||!$XX||!$QTY||!$SHIP_OVOY||!$OVOY||!$TD_NO){
					continue;
				}

				if($EUSE_DD>0){

					$EUSE_DD=PHPExcel_Shared_Date::ExcelToPHP($EUSE_DD);

					$timezone = Conf::get('time_zone');

					$EUSE_DD -= ($timezone * 3600);

					$EUSE_DD = local_date('Y-m-d H:i',$EUSE_DD);
					if(empty($EUSE_DD)){
						$EUSE_DD='';
					}
				}

				$sql="insert into T_UBOXPLAN(VC_NO,SHIP_NO,TD_NO,XX,QTY,USE_DD,REM,USR,COMP,COMP_NO,MK_DD,CUS_NO,OVOY,P_ADD,EUSE_DD,jj_flag,IMPORT)
		values('".$this->create_guidnew()."','".$SHIP_OVOY."','".$TD_NO."','".$XX."','".$QTY."','".local_date('Y-m-d H:i:s',gmtime())."','".$REM."',
		'".$u['user_name']."','".$salm['COMP']."','".$salm['COMPNO']."',
		'".local_date('Y-m-d H:i:s',gmtime())."','".$CUS_NO."','".$OVOY."','".$P_ADD."','".$EUSE_DD."','".$jj_flag."','Y')";
				$sqldb->query($sql);

				$ret_url="index.php?app=plan";
			}
			$this->show_message('操作成功','','index.php?app=plan');
			exit();
		}
	}

	function box(){
		$box_no = empty($_REQUEST['box_no']) ? '' : $_REQUEST['box_no'];
		$et_no = empty($_REQUEST['et_no']) ? '' : $_REQUEST['et_no'];

		$n = empty($_REQUEST['n']) ? '' : $_REQUEST['n'];
		$sqldb=&sqldb();
		$sql="select * from T_UBOXPLAN where VC_NO='".$n."'";
		$plan=$sqldb->getRow($sql);
		if(empty($plan)){
			$this->pons_error('info','要箱计划不存在');
			exit();
		}

		if(!$box_no){
			$this->pons_error('info','请输入箱号');
			exit();
		}

		if(!$et_no){
			$this->pons_error('info','堆场单号无效');
			exit();
		}

		$sql="exec PT_WEB_UBOX '".$plan['VC_NO']."','".$box_no."','".$et_no."','','".$u['user_name']."'";

		$plan=$sqldb->getRowp($sql);

		if($plan&&$plan['rem']!='OK'){
			$this->pons_error('info',$plan['rem']);
			exit();
		}

		$sql="update T_UBOXPLAN set QTY=QTY+1 where VC_NO='".$n."'";
		$sqldb->query($sql);

		$this->pons_result('index.php?app=plan&n='.$n);
		exit();

	}
	function stock(){
		$t = empty($_REQUEST['t']) ? '' : $_REQUEST['t'];
		$n = empty($_REQUEST['n']) ? '' : $_REQUEST['n'];

		if(empty($n)){
			echo '[]';
			exit();
		}

		$sqldb=&sqldb();
		$sql="select * from T_UBOXPLAN where VC_NO='".$n."'";
		$plan=$sqldb->getRow($sql);
		if(empty($plan)){
			echo '[]';
			exit();
		}

		$db=&db();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$sql="select * from T_SALM where SAL_NO='".$u['depot']."'";
		$salm=$sqldb->getRow($sql);

		$sql="exec PT_WEB_CURBOX '".$salm['COMPNO']."','".$plan['CUS_NO']."','".$plan['XX']."'";

		$plan=$sqldb->getAllp($sql);
		if($plan){
			echo json_encode($plan);
		}else{
			echo '[]';
		}
		exit();
	}

	function index()
	{
		$order=empty($_REQUEST['f']) ? 'USE_DD' : $_REQUEST['f'];
		$sort=empty($_REQUEST['s']) ? 'DESC' : $_REQUEST['s'];

		$n=empty($_REQUEST['n']) ? '' : $_REQUEST['n'];

		$this->assign('order', $order);
		$this->assign('sort', $sort);

		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$page = $this->_get_pagen(10);

		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];

		$sdefaultDate = date("Y/m/d");
		$week_start=date("Y/m/d",strtotime(date("Y/m/d"))-30*24*60*60);
		$week_end=$sdefaultDate;

		$bgn_dd = empty($_REQUEST['bgn_dd']) ? $week_start : $_REQUEST['bgn_dd'];
		$end_dd = empty($_REQUEST['end_dd']) ? $week_end : $_REQUEST['end_dd'];
		$this->assign('start', $bgn_dd);
		$this->assign('end', $end_dd);

		$conditions = ' and 1=1';
		if($k){
			$conditions.=" and (A.SHIP_NO like '%".$k."%' or A.TD_NO like '%".$k."%')";
		}

		if($bgn_dd){
			$conditions.=" and USE_DD>='".$bgn_dd."'";
		}
		if($end_dd){
			$conditions.=" and USE_DD<='".$end_dd." 23:59:59'";
		}

		if($n){
			$conditions.=" and A.VC_NO='".$n."'";
		}
		$this->assign('n', $n);

		$sql="SELECT *
FROM (SELECT A.SHIP_NO as SHIP_OVOY,A.OVOY,A.TD_NO,A.CUS_NO,A.XX,A.USE_DD,A.VC_NO,A.REM,A.MK_DD,A.USR,A.QTY,A.P_ADD,A.EUSE_DD,B.NAME as TXD,C.NAME as JG_ADD,D.NAME OTXD ,A.UTYPE,
ROW_NUMBER() OVER (ORDER BY A.USE_DD desc) AS RowNumber
FROM T_UBOXPLAN A LEFT JOIN CUST B ON A.SOUR=B.CUS_NO LEFT JOIN CUST C ON A.JG_ADD=C.CUS_NO LEFT JOIN CUST D ON A.OSOUR=D.CUS_NO     
where (A.USR='".$u['user_name']."' OR ISNULL(A.MK_USR,'')='".$u['user_name']."') and ISNULL(A.DEL_FLAG,'')!='T' ".$conditions.") T_UBOXPLANPage
WHERE RowNumber > ".$page['s']." AND RowNumber <= ".$page['e']."
ORDER BY $order $sort";
		$plan=$sqldb->getAll($sql);
		$list=array();
		if($plan){
			foreach ($plan as $v){
				
				if($v['USE_DD']){
					$v['USE_DD']=gmstr2time($v['USE_DD']);

					if(gmtime()-$v['USE_DD']>15*60){
						$v['UTYPE']='';
					}
				}

				if($v['EUSE_DD']){
					$v['EUSE_DD']=gmstr2time($v['EUSE_DD']);
				}
				$list[]=$v;
			}
		}

		$sql="select count(1) from T_UBOXPLAN A where (A.USR='".$u['user_name']."' OR ISNULL(A.MK_USR,'')='".$u['user_name']."') and ISNULL(DEL_FLAG,'')!='T' ".$conditions;
		$c=$sqldb->getOne($sql);

		$page['item_count'] = $c;
		$this->_format_pageweb($page);
		$this->assign('page_info', $page);

		$this->assign('plan', $list);

		$this->display('yplan.html');
	}

	function p()
	{
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$sql="select * from T_SALM where SAL_NO='".$u['depot']."'";
		$salm=$sqldb->getRow($sql);


		$sql="exec PT_WEB_CURSTOCK '".$salm['COMPNO']."',''";

		$plan=$sqldb->getAllp($sql);

		if($plan){
			foreach ($plan as $v){
				$sql="select sname from zys_shippingline where code='".$v['cus_no']."'";
				$s=$db->getOne($sql);
				if($s){
					$v['cus']=$v['cus_no'].' '.$s;
				}else{
					$v['cus']=$v['cus_no'];
				}
				$list[]=$v;
			}
		}

		$this->assign('plan', $list);

		$this->display('pplan.html');
	}

	function b()
	{
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);


		$sql="exec PT_WEB_ZDBOX '".$u['user_name']."',''";

		$plan=$sqldb->getAllp($sql);

		if($plan){
			foreach ($plan as $v){
				if($v['mk_dd']){
					$v['mk_dd']=gmstr2time($v['mk_dd']);
				}
				$list[]=$v;
			}
		}

		$this->assign('plan', $list);

		$this->display('bbplan.html');
	}

	function wsearch()
	{
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];
		$ss = empty($_REQUEST['s']) ? 'B' : $_REQUEST['s'];
		if($ss!='B'&&$ss!='O'){
			$ss='B';
		}

		$sql="exec PT_WWW_ONPLANLIST '".$u['user_name']."','".$ss."','".$k."'";

		$plan=$sqldb->getAllp($sql);

		$list=array();
		if($plan){
			foreach ($plan as $v){
				
				if($v['USE_DD']){
					$v['USE_DD']=gmstr2time($v['USE_DD']);
				}

				if($v['MK_DD']){
					$v['MK_DD']=gmstr2time($v['MK_DD']);
				}
				$list[]=$v;
			}
		}

		$this->assign('ss', $ss);
		$this->assign('plan', $list);

		$this->display('wsearch.html');
	}

	function wline()
	{
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$k = empty($_REQUEST['td']) ? '' : $_REQUEST['td'];
		$ss = empty($_REQUEST['s']) ? 'T' : $_REQUEST['s'];
		if($ss!='T'&&$ss!='D'){
			$ss='T';
		}

		$sql="exec PT_WWW_ONPLAN '".$k."','".$ss."'";

		$plan=$sqldb->getAll($sql);

		$list=array();

		if($ss=="T"){
			if($plan){
				foreach ($plan as $v){
					$list[]=$v;
				}
			}
			$this->assign('line', $list);
		}else{
			if($plan){
				foreach ($plan as $v){
					$list[$v['BOX_NO']]['box']=$v['BOX_NO'];
					$list[$v['BOX_NO']]['data'][]=$v;
				}
			}
			$this->assign('linebox', $list);
		}

		$this->assign('ss', $ss);
		$this->display('wline.html');
	}

	function fang()
	{
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);
		$page = $this->_get_pagen(10);

		$sdefaultDate = date("Y/m/d");

		$week_start=date("Y/m/d",strtotime(date("Y/m/d"))-7*24*60*60);
		$week_end=$sdefaultDate;

		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];
		$bgn_dd = empty($_REQUEST['bgn_dd']) ? $week_start : $_REQUEST['bgn_dd'];
		$end_dd = empty($_REQUEST['end_dd']) ? $week_end : $_REQUEST['end_dd'];
		$fdzt = empty($_REQUEST['fdzt']) ? 'N' : $_REQUEST['fdzt'];

		$sql="exec pt_uboxqry '".$u['user_name']."','".str_replace('/', '-', $bgn_dd)."','".str_replace('/', '-', $end_dd)."','".$k."','".$fdzt."'";
		$plan=$sqldb->getAll($sql);
		$list=array();
		if($plan){
			foreach ($plan as $v){
			
				if($v['USE_DD']){
					$v['USE_DD']=gmstr2time($v['USE_DD']);
				}
				if($v['MK_DD']){
					$v['MK_DD']=gmstr2time($v['MK_DD']);
				}

				$list[]=$v;
			}
		}

		$this->assign('start', $bgn_dd);
		$this->assign('end', $end_dd);
		$this->assign('plan', $list);
		$this->assign('fdzt', $fdzt);

		$sql="select * from zys_dictionary where d_code='fang' order by d_order";
		$fang=$db->getAll($sql);
		$this->assign('fang', $fang);

		$this->display('fang.html');
	}

	function fast(){
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$page = $this->_get_pagen(1);

		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];

		$conditions = ' and 1=1';
		if($k){
			$conditions.=" and (SHIP_NO like '%".$k."%' or TD_NO like '%".$k."%')";
		}

		$sql="SELECT *
FROM (SELECT SHIP_NO as SHIP_OVOY,OVOY,TD_NO,CUS_NO,XX,USE_DD,VC_NO,REM,MK_DD,USR,QTY,P_ADD,EUSE_DD,
ROW_NUMBER() OVER (ORDER BY USE_DD DESC) AS RowNumber
FROM T_UBOXPLAN where USR='".$u['user_name']."' and ISNULL(DEL_FLAG,'')!='T' ".$conditions.") T_UBOXPLANPage
WHERE RowNumber > 0 AND RowNumber <= 1
ORDER BY USE_DD DESC";
		$plan=$sqldb->getAll($sql);
		$list=array();
		if($plan){
			foreach ($plan as $v){
				
				if($v['USE_DD']){
					$v['USE_DD']=$v['USE_DD'];
				}
					
				if($v['EUSE_DD']){
					$v['EUSE_DD']=gmstr2time($v['EUSE_DD']);
				}
				$list[]=$v;
			}
		}

		$sql="select count(1) from T_UBOXPLAN where USR='".$u['user_name']."' and ISNULL(DEL_FLAG,'')!='T' ".$conditions;
		$c=$sqldb->getOne($sql);

		$page['item_count'] = $c;
		$this->_format_pageweb($page);
		$this->assign('page_info', $page);

		$this->assign('plan', $list);

		$sql="select * from zys_dictionary where d_code='boxtype' and d_del=1 order by d_order";
		$type=$db->getAll($sql);

		$this->assign('type', $type);

		$this->assign('d', time()+7*24*60*60);
		$this->display('fast.html');
	}

	function fastyd(){
		$sqldb=&sqldb();
		$his= empty($_REQUEST['his']) ? '' : $_REQUEST['his'];
		if(empty($his)){
			$this->pons_error('info','您没有选中任何数据');
			exit();
		}
		$his=array_values($his);
		$uid=$this->visitor->get("user_id");

		$db=&db();
		$sql="select depot,del,company,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		if($u['del']){
			$this->pons_error('info','用户被禁用，如有疑问请联系客服');
			exit();
		}

		if(!$u['depot']){
			$this->pons_error('info','用户还没有被系统确认，无法预定');
			exit();
		}

		$sql="select * from T_SALM where SAL_NO='".$u['depot']."'";
		$salm=$sqldb->getRow($sql);

		if(!$salm){
			$this->pons_error('info','用户还没有被系统确认，无法预定');
			exit();
		}

		foreach ($his as $v){
			if(empty($v['box'])){
				continue;
			}

			$CUS_NO = empty($v['CUS_NO']) ? '' : $v['CUS_NO'];
			$XX= empty($v['XX']) ? '' : $v['XX'];
			$QTY= empty($v['QTY']) ? 0 : intval($v['QTY']);
			$SHIP_OVOY= empty($v['SHIP_OVOY']) ? '' : $v['SHIP_OVOY'];
			$OVOY= empty($v['OVOY']) ? '' : $v['OVOY'];
			$TD_NO= empty($v['TD_NO']) ? '' : $v['TD_NO'];
			$USE_DD= empty($v['USE_DD']) ? '' : $v['USE_DD'];
			$REM= empty($v['REM']) ? '' : $v['REM'];
			$P_ADD= empty($v['P_ADD']) ? '' : $v['P_ADD'];

			if(!$CUS_NO){
				$this->pons_error('info','船公司无效');
				exit();
			}

			if(!$XX){
				$this->pons_error('info','请选择箱型');
				exit();
			}

			if(!$QTY){
				$this->pons_error('info','请输入箱量');
				exit();
			}

			if(!$SHIP_OVOY){
				$this->pons_error('info','请填写船名');
				exit();
			}

			if(!$OVOY){
				$this->pons_error('info','请填写航次');
				exit();
			}

			if(!$TD_NO){
				$this->pons_error('info','请填写提单号');
				exit();
			}

			if(!$USE_DD){
				$this->pons_error('info','请选择用箱时间');
				exit();
			}

			$sql="insert into T_UBOXPLAN(VC_NO,SHIP_NO,TD_NO,XX,QTY,USE_DD,REM,USR,COMP,COMP_NO,MK_DD,CUS_NO,OVOY,P_ADD)
		values('".$this->create_guidnew()."','".$SHIP_OVOY."','".$TD_NO."','".$XX."','".$QTY."','".$USE_DD."',
		'".$REM."','".$u['user_name']."','".$salm['COMP']."','".$salm['COMPNO']."',
		'".local_date('Y-m-d H:i:s',gmtime())."','".$CUS_NO."','".$OVOY."','".$P_ADD."')";
			$sqldb->query($sql);
		}

		$ret_url="index.php?app=plan";
		$this->pons_result($ret_url);
		exit();
	}

	function cus(){
		$k= empty($_REQUEST['k']) ? '' : $_REQUEST['k'];
		if(empty($k)){
			$this->pons_error('info','船公司不存在');
			exit();
		}
		$uid=$this->visitor->get("user_id");

		$db=&db();
		$sql="select * from zys_shippingline where code='".$k."' and isuse=1 order by sort_order limit 1";
		$cus=$db->getRow($sql);

		if(empty($cus)){
			$this->pons_error('info','船公司不存在');
			exit();
		}

		$m=array('success'=>'1','k'=>$cus['sname'],'c'=>$cus['code']);
		$this->pons_result1($m);
		exit();
	}

	function cancel(){
		$sqldb=&sqldb();
		$n= empty($_REQUEST['n']) ? '' : $_REQUEST['n'];
		if(empty($n)){
			$this->pons_error('info','要箱计划不存在');
			exit();
		}
		$u=$this->visitor->get("user_name");
		$sql="exec pt_uboxcheck '".$n."','".$u."'";
		$d=$sqldb->getRow($sql);

		if(empty($d)){
			$this->pons_error('info','操作失败,请重试');
			exit();
		}else{
			if($d['flag']=='F'){
				$this->pons_error('info',$d['ts']);
				exit();
			}
		}

		$this->pons_result('index.php?app=plan');
		exit();
	}

	function yong(){
		$sqldb=&sqldb();
		$code= empty($_REQUEST['code']) ? '' : $_REQUEST['code'];

		$xx= empty($_REQUEST['xx']) ? '' : $_REQUEST['xx'];
		$SHIP_OVOY= empty($_REQUEST['SHIP_OVOY']) ? '' : $_REQUEST['SHIP_OVOY'];
		$OVOY= empty($_REQUEST['OVOY']) ? '' : $_REQUEST['OVOY'];
		$TD_NO= empty($_REQUEST['TD_NO']) ? '' : $_REQUEST['TD_NO'];

		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);
		if(empty($uid)){
			$this->pons_error('info','您还没有登录，请先登录');
			exit();
		}

		$db=&db();
		$sql="select depot,del,company,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		if($u['del']){
			$this->pons_error('info','用户被禁用，如有疑问请联系客服');
			exit();
		}

		if(!$u['depot']){
			$this->pons_error('info','用户还没有被系统确认，无法预定');
			exit();
		}

		$sql="select * from T_SALM where SAL_NO='".$u['depot']."'";
		$salm=$sqldb->getRow($sql);

		if(!$salm){
			$this->pons_error('info','用户还没有被系统确认，无法预定');
			exit();
		}

		if(!$xx){
			$this->pons_error('info','箱型无效');
			exit();
		}

		if(!$code){
			$this->pons_error('info','船公司无效');
			exit();
		}

		if(!$SHIP_OVOY){
			$this->pons_error('info','请填写船名');
			exit();
		}

		if(!$OVOY){
			$this->pons_error('info','请填写航次');
			exit();
		}

		if(!$TD_NO){
			$this->pons_error('info','请填写提单号');
			exit();
		}

		$n=$this->create_guidnew();
		$sql="insert into T_UBOXPLAN(VC_NO,SHIP_NO,TD_NO,XX,QTY,USE_DD,REM,USR,COMP,COMP_NO,MK_DD,CUS_NO,OVOY,P_ADD,EUSE_DD,UTYPE)
		values('".$n."','".$SHIP_OVOY."','".$TD_NO."','".$xx."','0','".local_date('Y-m-d H:i:s',gmtime())."','',
		'".$u['user_name']."','".$salm['COMP']."','".$salm['COMPNO']."',
		'".local_date('Y-m-d H:i:s',gmtime())."','".$code."','".$OVOY."','','','ZD')";
		$sqldb->query($sql);

		$this->pons_result('index.php?app=plan&n='.$n);
		exit();
	}


	function wl(){
		$sqldb=&sqldb();
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);
		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$wl=array();

		$sql="exec PT_WWW_UsrWl '".$u['user_name']."','".$k."','T'";
		$temp=$sqldb->getAll($sql);
		if($temp){
			foreach ($temp as $v){
				if($v['USE_DD']){
					//$v['USE_DD']=gmstr2time($v['USE_DD']);
				}
				$v['td_no']=str_replace(' ', '', $v['td_no']);

				$sub=array();
				$sql="exec PT_WWW_UsrWl '".$u['user_name']."','".$v['td_no']."','D'";
				$temp1=$sqldb->getAll($sql);
				if($temp1){
					foreach ($temp1 as $v1){
						if($v1['fd_dd']){
							$v1['fd_dd']=gmstr2time($v1['fd_dd']);
						}
						if($v1['pc_dd']){
							$v1['pc_dd']=gmstr2time($v1['pc_dd']);
						}
						if($v1['et_dd']){
							$v1['et_dd']=gmstr2time($v1['et_dd']);
						}
						if($v1['ec_dd']){
							$v1['ec_dd']=gmstr2time($v1['ec_dd']);
						}
						if($v1['tc_dd']){
							$v1['tc_dd']=gmstr2time($v1['tc_dd']);
						}
						if($v1['jg_dd']){
							$v1['jg_dd']=gmstr2time($v1['jg_dd']);
						}
						$sub[]=$v1;
					}
				}
				$v['sub']=$sub;

				$wl[]=$v;
			}
		}

		$this->assign('wl', $wl);
		$this->display('wl.html');
	}

	function fee(){
		$sqldb=&sqldb();
		
		$sdefaultDate = date("Y/m/d");
		$week_start=date("Y/m/d",strtotime(date("Y/m/d"))-30*24*60*60);
		$week_end=$sdefaultDate;

		$bgn_dd = empty($_REQUEST['bgn_dd']) ? $week_start : $_REQUEST['bgn_dd'];
		$end_dd = empty($_REQUEST['end_dd']) ? $week_end : $_REQUEST['end_dd'];
		$this->assign('start', $bgn_dd);
		$this->assign('end', $end_dd);
		
		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);
		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];

		$db=&db();
		$sql="select depot,user_name from zys_member where user_id=".$uid;
		$u=$db->getRow($sql);

		$wl=array();

		$sql="exec PT_WWW_Usrfee '".$u['user_name']."','".$bgn_dd."','".$end_dd."','".$k."','T'";
		$fee=$sqldb->getAll($sql);

		$this->assign('fee', $fee);
		$this->display('fee.html');
	}
}

?>
